package uk.ac.lkl.common.ui;



//import java.awt.Component;


/**
 * A view creator that passes some context when creating views.
 * 
 * In general, <code>ViewCreator</code>s just take a model and
 * construct a view (a JPanel). In some circumstances, however, it is
 * useful to be able to pass more than just the model. This class
 * provides for this contingency.
 * 
 * @author Darren Pearce
 * @version $Revision$
 * @version $Date$
 * 
 */
public abstract class ContextualisedViewCreator<O, C> extends ViewCreator<O> {

    /**
     * The context to pass when creating views.
     * 
     */
    private C context;


    /**
     * Create a new instance that uses the given context when creating
     * views.
     * 
     * @param context
     */
    public ContextualisedViewCreator(
                                     C context) {
        setContext(context);
    }


    /**
     * Set the context of the instance.
     * 
     * @param context
     *            the context
     * 
     */
    public void setContext(C context) {
        this.context = context;
    }


    /**
     * Create a view from the specified model.
     * 
     * This overrides the base-class methods and chains the call on to
     * <code>createView(model, context)</code> using the context
     * specified at construction time.
     * 
     * @param model
     *            the model
     * 
     * @return a view of the model
     * 
     */
    @Override
    public final View<O> createView(O model) {
        return createView(model, context);
    }


    /**
     * Create a view using the specified model and accompanying
     * context.
     * 
     * @param model
     *            the model
     * @param context
     *            the context
     * 
     * @return a view of the model
     * 
     */
    protected abstract View<O> createView(O model, C context);

}